
const datas = {
	articles:[
    {
        "id":"1010",
		"title": "坐火车需要核酸报告吗？重庆车站最新防疫规定get一下",
        "date": "2022-10-24",
        "name": "Harlan Douglas"
    },
    {
       
		"id":"1987",
		"title": "长江旅游研究基地首席专家罗兹柏：成渝文旅新地标评选助力川渝“中部塌陷”地区快速发展,长江旅游研究基地首席专家罗兹柏：成渝文旅新地标评选助力川渝“中部塌陷”地区快速发展",
        "date": "2020-11-08",
        "name": "Stacy Prince"
    },
    {
        "id":"342",
		"title": "海淀区芙蓉里小区解封之后，居民凭声音认出了他们",
        "date": "2022-02-03",
        "name": "Elton Caldwell"
    },
    {
       "id":"1358",
		"title": "新冠口服药终结疫情？病毒将自我消亡？世卫回应",
        "date": "2022-04-27",
        "name": "Yvonne Santiago"
    },
    {
        "id":"2498",
		"title": "人民财评：让进博会四大平台的金字招牌越擦越亮",
        "date": "2022-05-16",
        "name": "Prescott Fletcher"
    }
	],
	experts:[
		{
			"id":'1',
			"headImg":'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
			"name":"张三",
			"sex":'男',
			"phone":'13573141640',
			"password":'123456',
			"status":'1',
			"createDate":'2018-7-19',
			"lastTime":'2021-4-12',
			"company":'济南市中心医院',
			"specialty":'儿科',
			"numberCard":'100018965431'
		},
		{
			"id":'2',
			"headImg":'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
			"name":"李四",
			"sex":'男',
			"phone":'13573141640',
			"password":'123456',
			"status":'1',
			"createDate":'2018-7-19',
			"lastTime":'2021-4-12',
			"company":'济南市中心医院',
			"specialty":'儿科',
			"numberCard":'100018965431'
		}
	]
	}
module.exports = {
    devServer: {
        port: 8090,
		proxy:{
			'/api':{
				 target: "http://localhost:8080", //目标地址，一般是指后台服务器地址
				        changeOrigin: true, //是否跨域
				        pathRewrite: { // pathRewrite 的作用是把实际Request Url中的'/api'用""代替
				          '^/api': "" 
				        }
			},
			'/wx':{
				target: "https://open.weixin.qq.com", //目标地址，一般是指后台服务器地址
				       changeOrigin: true, //是否跨域
				       pathRewrite: { // pathRewrite 的作用是把实际Request Url中的'/api'用""代替
				         '^/wx': "" 
				       }
			}
		},
        before: function (app, server, compiler) {
            app.get('/all', function (req, res) {
                res.json({"data": datas.articles})
            });

            app.get('/page/:page/:limit', function (req, res) {
                let page = req.params.page
                let limit = req.params.limit
                // 对数据进行分页
                let result = datas.articles.slice((page - 1) * limit, page * limit)

                res.json({
                    'total': datas.articles.length,
                    'data': result
                })
            });

            app.get('/where/:page/:limit', function (req, res) {
                // 路由参数接收
                let page = req.params.page
                let limit = req.params.limit
                // get参数接收
                let title = req.query.title
                let time = req.query.time
			
                // req.body     

                let results = []
                // 筛选出符合条件的数据
                datas.articles.forEach(item => {
                    let r=(title == undefined || title.length == 0) ? true : item.title.includes(title)
                    let l=(time == undefined || time.length == 0) ? true : item.date == time
                    let a = r&&l
                    if (a){
                        results.push(item)
                    }
                })
                // 对符合条件的数据进行分页
                let result = results.slice((page - 1) * limit, page * limit)

                res.json({
                    'total': results.length,
                    'data': result
                })
            });
			//查询所有专家
			app.get('/expertsPage/:page/:limit', function (req, res) {
			    let page = req.params.page
			    let limit = req.params.limit
			    // 对数据进行分页
			    let result = datas.experts.slice((page - 1) * limit, page * limit)
			
			    res.json({
			        'total': datas.experts.length,
			        'data': result
			    })
			});
			//根据ID查询专家信息
			app.get('/expertsById/:id', function (req, res) {
			   
			    let id = req.params.id
			    let results ={}
			    // 筛选出符合条件的数据
			    datas.experts.forEach(item => {
			      
			        if (item.id==id){
			            results=item
			        }
			    })
			    res.json({
			        'total': 1,
			        'data': results
			    })
			});
        }
    }
}